package com.code.config;


import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.io.File;

/**
 * WebMvc配置
 */
@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {


        // swagger-ui doc enable
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");




        // 上传文件的静态资源映射
        WebProperties webproperties = new WebProperties();
        String filesSavePath = webproperties.getFileSavePath();
        if (!filesSavePath.endsWith(File.separator)) {
            filesSavePath += File.separator;
        }
        registry.addResourceHandler("/static/**"/*, "/favicon.ico"*/)
                .addResourceLocations("classpath:/static/", "file:" + filesSavePath);

        // super.addResourceHandlers(registry);
    }



}
